package com.gerencia.view;

import com.gerencia.log.LogErrors;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author icarlos
 */
public class Login extends JFrame {

    FileWriter fw;
    BufferedWriter bw;

    public Login() {
        initComponents();
        try {
            fw = new FileWriter("/home/icarlos/NetBeansProjects/GerenciaCondominio/src/com/gerencia/log/archive_error");
            bw = new BufferedWriter(fw);

            bw.write(jCBLoginUser.getSelectedItem().toString());
            bw.newLine();
            bw.write(jPFSenha.getText().toString());
            
            bw.close();
        } catch (IOException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLLogin = new javax.swing.JLabel();
        jCBLoginUser = new javax.swing.JComboBox();
        jLSenha = new javax.swing.JLabel();
        jPFSenha = new javax.swing.JPasswordField();
        jBLogar = new javax.swing.JButton();
        jBCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setUndecorated(true);
        getContentPane().setLayout(null);

        jLLogin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/gerencia/image/couple48.png"))); // NOI18N
        jLLogin.setText("Login");
        getContentPane().add(jLLogin);
        jLLogin.setBounds(20, 30, 110, 50);

        jCBLoginUser.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "User" }));
        jCBLoginUser.setToolTipText("Login User");
        getContentPane().add(jCBLoginUser);
        jCBLoginUser.setBounds(150, 40, 320, 27);

        jLSenha.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/gerencia/image/search24.png"))); // NOI18N
        jLSenha.setText("Senha ");
        getContentPane().add(jLSenha);
        jLSenha.setBounds(20, 94, 110, 30);

        jPFSenha.setToolTipText("Password User");
        getContentPane().add(jPFSenha);
        jPFSenha.setBounds(150, 90, 320, 27);

        jBLogar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/gerencia/image/success24.png"))); // NOI18N
        jBLogar.setText("Logar ");
        jBLogar.setToolTipText("Logar");
        jBLogar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBLogarActionPerformed(evt);
            }
        });
        getContentPane().add(jBLogar);
        jBLogar.setBounds(160, 140, 130, 36);

        jBCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/gerencia/image/cancel24.png"))); // NOI18N
        jBCancel.setText("Cancelar ");
        jBCancel.setToolTipText("Cancelar");
        jBCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelActionPerformed(evt);
            }
        });
        getContentPane().add(jBCancel);
        jBCancel.setBounds(310, 140, 140, 36);

        setSize(new java.awt.Dimension(489, 197));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jBCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jBCancelActionPerformed

    private void jBLogarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBLogarActionPerformed

        if (jCBLoginUser.getSelectedItem().equals("User") && jPFSenha.getText().equals("admin")) {
            int opt = JOptionPane.OK_OPTION;
            if (opt == JOptionPane.OK_OPTION) {
                JOptionPane.showMessageDialog(this, "Você está LOGADO!", "Seja Bem Vindo ao Sistema", JOptionPane.INFORMATION_MESSAGE);
                System.exit(0);
            }
        } else {
            JOptionPane.showMessageDialog(this, "Usuário não encontrado", "Aviso", JOptionPane.WARNING_MESSAGE);
            System.exit(0);
        }
    }//GEN-LAST:event_jBLogarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Login().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCancel;
    private javax.swing.JButton jBLogar;
    private javax.swing.JComboBox jCBLoginUser;
    private javax.swing.JLabel jLLogin;
    private javax.swing.JLabel jLSenha;
    private javax.swing.JPasswordField jPFSenha;
    // End of variables declaration//GEN-END:variables
}
